package com.ironman.original.generator;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.ironman.event.threadpool.ThreadPool;
import org.noear.snack.ONode;

import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

public abstract class OriginalDataGenerator {

    public void start(String mHmId, Consumer<String> consumer) {
        ThreadPool.SCHEDULED_EXECUTOR.scheduleAtFixedRate(() -> {
            ONode node = ONode.newObject()
                    .set("dataType", dataType())
                    .set("hmId", mHmId)
                    .set("ts", DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN))
                    .set("data", generate());
            consumer.accept(node.toJson());
        }, 0, 1, TimeUnit.SECONDS);
    }

    abstract String dataType();

    abstract String generate();
}
